//Promise 形式的getSetting 获取用户地址
export const getSetting = () => {
    return new Promise((resolve, reject) => {
        wx.getSetting({
            success: (result) => {
                resolve(result);
            },
            fail: (err) => {
                reject(err);
            },
            complete: () => {}
        });

    })
}

//Promise 形式的 chooseAddress 获取用户地址
export const chooseAddress = () => {
    return new Promise((resolve, reject) => {
        wx.chooseAddress({
            success: (result) => {
                resolve(result);
            },
            fail: (err) => {
                reject(err);
            },
            complete: () => {}
        });

    })
}

//Promise 形式的 openSetting 获取用户地址
export const openSetting = () => {
    return new Promise((resolve, reject) => {
        wx.openSetting({
            success: (result) => {
                resolve(result);
            },
            fail: (err) => {
                reject(err);
            },
            complete: () => {}
        });
    })
}

//Promise 形式的 showModal  提示弹出框
export const showModal = ({content}) => {
    return new Promise((resolve, reject) => {
        wx.showModal({
            title: '提示',
            content: content, // 很有可能是后期后面传来的这里设置参数
            showCancel: true,
            cancelText: '取消',
            cancelColor: '#000000',
            confirmText: '确定',
            confirmColor: '#3CC51F',
            success: (result) => {
                resolve(result);
            },
            fail: (err) => {
                reject(err);
            },
            complete: () => {}
        });
    })
}

//Promise 形式的 showToast  提示弹出框
export const showToast = ({title}) => {
    return new Promise((resolve, reject) => {
        wx.showToast({
            title: title,
            icon: 'none',
            image: '',
            duration: 1500,
            mask: false,
            success: (result)=>{
              resolve(result);
            },
            fail: (err)=>{
                reject(err);
            },
            complete: ()=>{}
          });
    })
}

//Promise 形式的 login 登录获取权限
export const login=()=>{
    return new Promise((resolve,reject)=>{
      wx.login({
        timeout:10000,
        success: (result) => {
          resolve(result);
        },
        fail: (err) => {
          reject(err);
        },
        complete: ()=>{}
      });
    })
}

//Promise 形式的 requestPayment 微信支付
export const requestPayment=(pay)=>{
    return new Promise((resolve,reject)=>{
     wx.requestPayment({
        ...pay,
       success: (result) => {
        resolve(result)
       },
       fail: (err) => {
         reject(err);
       }
     });
       
    })
  }